// pages/routeDetail/index.js
var util = require('../../utils/util.js');
var WxParse = require('../../utils/wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nowActive: '',
    current: 0,
    routeInfo: '',
    id: '',
    userInfo: '',
    line_item: '',
    notice: '',
    userComment: [],
    trip_content: [],
    tabTag: 0,
    isShare: false,
    shareNum: '',
    isPoster: false,
    posters: '',
    recom_uid: '',
    circleId: ''
    
  },

  toPay: function (e) {
    if (this.data.userInfo === '') {
      wx.showToast({
        title: '未登录,跳转登录中...',
        icon: 'none',
        duration: 2000
      })
      setTimeout(item=>{
        wx.reLaunch({
          url: '/pages/index/index?id=4'
        })
      }, 1000)
      
      return false;
    }
    if (this.data.nowActive === '') {
      wx.showModal({
        content: '未选择出发日期',
        showCancel: false
      })
      this.goTop();
      return false;
    }
    if (e.currentTarget.dataset.state == '立即报名') {
      let data = {
        user_id: this.data.userInfo.user_id,
        line_id: this.data.id,
        line_time_id: this.data.nowActive
      }
      if(this.data.circleId !== '') {
        data.recom_uid = this.data.circleId
      } else {
        var recom_uid = wx.getStorageSync('recomUid')
        if (recom_uid) {
          data.recom_uid = recom_uid
        }
      }
      
      wx.setStorage({
        key: 'orderInfo',
        data: data
      })
      wx.navigateTo({
        url: '/pages/firmOrder/index',
      })
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.userInfo = util.isLogin();
    this.data.id = options.id;
    this.lineEvaluate(options.id);
  },
  
  lineEvaluate(id) {
    let that = this;
    util.http({
      url: '/api/miniwechat/line/evaluate',
      data: {
        line_id: id
      }
    }).then((data) => {
      console.log("lineEvaluate evaluate result------↓↓↓↓")
      console.log(data);
      this.setData({
        userComment: data
      })
    }).catch((err) => {
      wx.showToast({
        title: String(err),
        icon: 'none',
        duration: 2000
      })
    })
  }
})